import Vue from 'vue'
import VueRouter from 'vue-router'
// import { Toast } from 'vant'

// 首页
const Home = () => import(/* webpackChunkName: "home" */ '../views/Home')
// 发现页
const Discover = () => import(/* webpackChunkName: "discover" */ '../views/Discover/Discover')
// 个人中心
const My = () => import(/* webpackChunkName: "my-login" */ '../views/My/My')
// 测试页
const Test = () => import('../views/Test')
// 登录中心
const Login = () => import(/* webpackChunkName: "my-login" */ '../views/Login/Login')
// 搜索页面
const Search = () => import(/* webpackChunkName: "Search" */ '../views/Search/Search')
// 云村
const CloudVillage = () => import(/* webpackChunkName: "cloud-village-detail" */ '../views/CloudVillage/CloudVillage')
// 云村详情
const TopicDetail = () => import(/* webpackChunkName: "cloud-village-detail" */ '../views/CloudVillage/components/TopicDetail')
// 视频
const Video = () => import(/* webpackChunkName: "Video" */ '../views/Video/Video')
// 歌手页
const SingerPage = () => import(/* webpackChunkName: "group-Singer" */ '../views/SingerPage/SingerPage')
// 歌手音乐
const PlayMusic = () => import(/* webpackChunkName: "group-Singer" */ '../views/playMusic/PlayMusic')

// 全局注册
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '',
        name: 'Discover',
        component: Discover,
        meta: { title: '发现页', tabbar: true }
      },
      {
        path: '/home/my',
        name: 'My',
        component: My,
        meta: { title: '个人中心', tabbar: true }
      },
      {
        path: '/home/test',
        name: 'Test',
        component: Test,
        meta: { title: '测试页', tabbar: true }
      },
      {
        path: '/home/video',
        name: 'Video',
        component: Video,
        meta: { title: '视频', auth: true, tabbar: true }
      },
      {
        path: '/home/cloudVillage',
        name: 'CloudVillage',
        component: CloudVillage,
        meta: { title: '云村', auth: true, tabbar: true }
      }
    ]
  },
  {
    path: '/singersage',
    name: 'SingerPage',
    component: SingerPage,
    meta: { title: '歌手列表' }
  },
  {
    path: '/topicDetail/:id',
    name: 'TopicDetail',
    component: TopicDetail
  },
  {
    path: '/search',
    name: 'Search',
    component: Search,
    meta: { title: '音乐搜索' }

  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { title: '帐号登录' }

  },
  {
    path: '/playmusic/:SingerId',
    name: 'PlayMusic',
    component: PlayMusic,
    props: true,
    meta: { title: '歌手音乐' }
  }
]
// 创建路由
const router = new VueRouter({
  routes
})
// 路由前守卫
// router.beforeEach((to, from, next) => {
// if (to.meta.auth) {
//   const token = sessionStorage.getItem('token')
//   if (!token) {
//     Toast('你需要先登录帐号！')
//     next('/login')
//   }
//   next()
// } else {
//   next()
// }
// })
// 路由后守卫
router.afterEach((to, from) => {
  document.title = to.meta.title || '音乐'
})
export default router
